package cn.edu.nju.software.cdiy.algorithm.performance;

import cn.edu.nju.software.cdiy.bean.CPU;
import cn.edu.nju.software.cdiy.util.Constant;

public class CPUEvaluator implements Evaluator<CPU> {
	public double getPerformance(CPU c){
		//主频得分masterFreqScore
		double masterFreq = c.getMasterFrequency();
		double masterFreqScore = getMasterFreqBase(masterFreq)*Constant.CPU_STD_MASTERFREQUENCY;
		
		//超线程htScore
		int ht = c.getHT();
		double htScore = 0;
		if(ht==0) htScore=80;
		else htScore=100;
		htScore = htScore * Constant.CPU_STD_HT;
		
		//虚拟化 virScore
		int vir = c.getVIRTUALIZATION();
		double virScore = 0;
		if(vir==0) virScore = 80;
		else virScore = 100;
		virScore = virScore*Constant.CPU_STD_VIRTUALIZATION;
		
		//核心数量coreNumScore
		int coreNum = Integer.parseInt(c.getCoreNum().getValue());
		double coreNumScore = getCoreNumBase(coreNum)*Constant.CPU_STD_CORENUM;
		
		//制作工艺manuTechScore
		String manuTech = c.getManuTech().getValue();
		double manuTechScore = getManuTechBase(manuTech)*Constant.CPU_STD_MANUTECH;
		
		//turbo boost turboBoostScore
		int turboBoost = c.getTURBOBOOST();
		double turboBoostScore = 0;
		if(turboBoost == 0) turboBoostScore=80;
		else turboBoostScore=100;
		turboBoostScore = turboBoostScore*Constant.CPU_STD_TURBOBOOST;
		
		
		double score = masterFreqScore + htScore+virScore+coreNumScore+manuTechScore+turboBoostScore;
		
		return score;
		
	}

	private double getManuTechBase(String manuTech) {
		/*
		 * 制作工艺基础分
		 * 22		100
		 * 32		90
		 * 45		80
		 * 65		70
		 * 90		60
		 * */
		if(manuTech.equals("22nm"))
			return 100;
		else if(manuTech.equals("32nm"))
			return 90;
		else if(manuTech.equals("45nm"))
			return 80;
		else if(manuTech.equals("65nm"))
			return 70;
		else if(manuTech.equals("90nm"))
			return 60;
		
		return 0;
	}

	private double getCoreNumBase(int coreNum) {
		/*
		 * 核心数量基础分
		 * 1			50
		 * 2			60
		 * 3			70
		 * 4			80
		 * 6			90
		 * 8			95
		 * 大于8			100
		 * */
		if(coreNum==1)
			return 50;
		else if(coreNum==2)
			return 60;
		else if(coreNum==3)
			return 70;
		else if(coreNum==4)
			return 80;
		else if(coreNum==6)
			return 90;
		else if(coreNum==8)
			return 95;
		else if(coreNum>8)
			return 100;
		
		return 0;
	}

	private double getMasterFreqBase(double masterFreq) {
		/*
		 * 主频基础分
		 * 1.8及以下		60
		 * 1.8-2.4		70
		 * 2.4-2.8		80
		 * 2.8-3		90
		 * 3以上			100
		 * */
		if(masterFreq<=1.8)
			return 60;
		else if(masterFreq>1.8 && masterFreq<=2.4)
			return 70;
		else if(masterFreq>2.4 && masterFreq<=2.8)
			return 80;
		else if(masterFreq>2.8 && masterFreq<=3)
			return 90;
		else if(masterFreq>3)
			return 100;
		
		return 0;
	}
}	
